package com.ddwl.user.mq;

import com.alibaba.fastjson.JSON;
import com.ddwl.common.config.DingTalkNotify;
import com.ddwl.common.constant.RabbitMqConstants;
import com.ddwl.schema.vo.funds.OrderPaymentVo;
import com.ddwl.user.service.UpgradeAgentOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author hemiaojun
 * @Date 2021/9/24 10:04
 */
@Component
@Slf4j
public class RabbitMqReceiver {

    @Resource
    private UpgradeAgentOrderService upgradeAgentOrderService;

    @Resource
    private DingTalkNotify dingTalkNotify;


    @RabbitListener(bindings = {@QueueBinding(value = @Queue(value = RabbitMqConstants.UPGRADE_AGENT_QUEUE, durable = "true"),
            exchange = @Exchange(value = RabbitMqConstants.UPGRADE_AGENT_EXCHANGE), key = RabbitMqConstants.UPGRADE_AGENT_QUEUE)})
    public void upgradeAgentNotify(String orderPayment) {
        OrderPaymentVo orderPaymentVo = JSON.parseObject(orderPayment, OrderPaymentVo.class);
        log.info("开始处理用户升级代理付款消息 orderPaymentVo={}",JSON.toJSONString(orderPaymentVo));
        try {
            upgradeAgentOrderService.orderPayCallBack(orderPaymentVo);
        }catch (Exception e){
            log.error( "用户升级代理付款消息处理出错 orderPaymentVo={}"+JSON.toJSONString(orderPaymentVo),e);
            dingTalkNotify.exceptionNotify(e);
        }

    }


}
